package com.zhbit.action;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;
import com.zhbit.dao.StudentScoreDaoImpl;
import com.zhbit.domain.StudentScore;
import com.zhbit.service.StudentScoreService;
import com.zhbit.service.StudentScoreServiceImpl;

public class StudentScoreAction extends ActionSupport {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int id;
	private String username;
	private String subject;
	private float score;
	private int pageNo;
	private StudentScore stuscore;
	@Resource
	private StudentScoreService stuscoreService;
	
	
	

	public StudentScoreService getStuscoreService() {
		return stuscoreService;
	}

	public void setStuscoreService(StudentScoreService stuscoreService) {
		this.stuscoreService = stuscoreService;
	}

	public StudentScore getStuscore() {
		return stuscore;
	}

	public void setStuscore(StudentScore stuscore) {
		this.stuscore = stuscore;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	

	
	public float getScore() {
		return score;
	}

	public void setScore(float score) {
		this.score = score;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	public String Add() {
		boolean is = stuscoreService.add(stuscore.getId(),stuscore.getUsername(),stuscore.getSubject(),stuscore.getScore());
		if (is) {
			return SUCCESS;
		} else {
			return LOGIN;
		}
	}

	//分页查找学生
	public String findstu(){
		List list = stuscoreService.findByPage(pageNo);
		HttpServletRequest request = ServletActionContext.getRequest();  
        request.setAttribute("list", list);  
		return SUCCESS;
	}
	//修改学生信息
	public String Update(){
		//stuscoreservice = new StudentScoreServiceImpl();
		//StudentScoreDaoImpl stuscoredao = new StudentScoreDaoImpl();
		StudentScore stuscore = new StudentScore();
		stuscore.setId(id);
		stuscore.setUsername(username);
		stuscore.setSubject(subject);
		stuscore.setScore(score);
		if(stuscoreService.update(stuscore)){
			return SUCCESS;
		}else{
			return LOGIN;
		}
	}
	//删除学生
	public String Delstu(){
		//stuscoreservice = new StudentScoreServiceImpl();
		//StudentScoreDaoImpl stuscoredao = new StudentScoreDaoImpl();
		StudentScore stuscore = new StudentScore();
		stuscore.setId(id);
		stuscore.setUsername(username);
		stuscore.setSubject(subject);
		stuscore.setScore(score);
		if(stuscoreService.delstu(stuscore)){
			return SUCCESS;
		}else{
			return LOGIN;
		}
	}
}
